package com.example.author.controller;



import com.example.author.entity.Author;
import com.example.author.service.IAuthorService;
import com.example.common.dtos.ResponseResult;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 凡哥哥
 * @since 2023-11-20
 */
@RestController
@RequestMapping("/author")
@Slf4j
@CrossOrigin
public class AuthorController {
    @Autowired
    private IAuthorService authorService;

    /**
     * 作者登录
     * @param password,phone
     * @return
     */
    @GetMapping("/login")
    public ResponseResult login(String phone, String password){
        return authorService.login(phone,password);
    }



    /*注册*/
    @GetMapping("/code")
    public ResponseResult<String> sendCode(String phone) {
        return authorService.sendCode(phone);
    }


    @PostMapping("/register")
    public ResponseResult<String> register(@io.swagger.v3.oas.annotations.parameters.RequestBody Author author){
        return authorService.register(author);
    }

    /**
     * 退作者出
     * @return
     */
    @ApiOperation(value = "退出")
    @PostMapping("logout")
    public ResponseResult logout(){
        return ResponseResult.okResult("退出登陆成功");
    }
}

